home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / bteasy14.zip / BOOT.ASM next >
Assembly Source File  |  1993-04-25  |  8KB  |  299 lines

  1. ; BOOTEASY, version 1.4.
  2. ; Developed from BOOTANY, with many imrovements.
  3. ; The main idea was to simplify the installation
  4. ; procedure and to remove unnecessary partition type switching.
  5. ; Second hard disk switching added.
  6. ; Author: Serge Vakulenko, <vak@kiae.su>
  7.  
  8. F1_scancode     equ     59        ; scancode of 'F1' key
  9. Enter_scancode    equ    28        ; scancode of 'Enter' key
  10. Timeout        equ     5        ; wait up to 5 seconds for reply
  11.  
  12. StdBase        equ     7c00h        ; address where DOS loads us
  13. Base        equ    600h        ; address where we rewrite itself
  14. Partab        equ    1beh        ; partition table offset
  15. NumDisks    equ    475h        ; number of disk drives (BIOS data area)
  16.  
  17. BootIndicator   equ    0        ; partition record: boot indicator
  18. BeginHead       equ    1        ; first partition sector: head number
  19. BeginSector     equ    2        ; sector and cylinder
  20. SystemId        equ    4        ; system type
  21.  
  22. ; -------------------------------
  23.  
  24. dummy        segment at 0
  25.         assume  cs:dummy
  26.         org    Base        ; address where we rewrite itself
  27. BaseEntry:
  28.         org    StdBase        ; address where DOS loads us
  29. StdBaseEntry:
  30. dummy        ends
  31.  
  32. ; -------------------------------
  33.  
  34. code        segment 
  35.         assume  cs:code, ds:code, es:code, ss:code
  36.         org     0
  37. Boot:
  38. ;
  39. ;               Setup the stack and segment registers
  40. ;
  41.         xor    AX,AX        ; Zero register
  42.         mov    ES,AX        ; ES := 0
  43.         mov    DS,AX        ; DS := 0
  44.         cli            ; Disable interrupts
  45.         mov    SS,AX        ; SS := 0
  46.         mov    SP,StdBase    ; SP at 7c00
  47.         sti            ; Enable interrupts
  48. ;
  49. ;               DOS loads this pgm at 0000:7C00. Any boot routine
  50. ;               we call also expects to execute there so the first
  51. ;               exercise is to move this code somewhere else.
  52. ;
  53.         cld            ; Clear direction
  54.         mov    SI,SP        ; Copy from 7c00h...
  55.         mov    DI,Base        ; ...to 600h...
  56.         mov    CX,256        ; ...512 bytes, or 256 words
  57.         repne    movsw        ; Move itself to new location
  58.  
  59.         jmp    FAR PTR BaseEntry+(Entry-Boot)
  60.  
  61. ; -------------------------------
  62. ;
  63. ;               A valid function key was depressed (or defaulted)
  64. ;               Attempt to boot the corresponding partition.
  65. ;
  66. Load:
  67.         mov    DX,BP        ; restore drive number
  68.         pop    AX        ; key '1'..'5'
  69.         mov     Base+default,AL    ; save function key number
  70.         cmp    AL,'5'
  71.         je    SwitchDrive
  72.         mov    AH,16
  73.         mul    AH        ; AX = key * 16
  74.         add    AX,Base+Partab-'1'*16 ; subtract '1'
  75.         mov    SI,AX
  76. ;
  77. ;               Check if the partition is empty.
  78. ;
  79.         test    BYTE PTR SystemId[SI],0ffh
  80.         je      Menu        ; Yes - display menu again
  81.  
  82.         mov     BYTE PTR BootIndicator[SI],80h ; Mark partition as bootable
  83.         call    SaveBoot
  84. ;
  85. ;               Read in and validate the partition's boot sector.
  86. ;
  87.         mov     DH,BeginHead[SI] ; head from partition table
  88.         mov     CX,BeginSector[SI]
  89.         jmp    loadboot
  90. ;
  91. ;               Read in the boot sector from second disk.
  92. ;
  93. SwitchDrive:
  94.         call    SaveBoot
  95.         mov     CX,0001h    ; cylinder 0, sector 1
  96.         xor    DL,CL        ; (DL ^= 1) switch drive
  97. loadboot:
  98.         mov    BX,StdBase    ; ES already == 0
  99.         mov     AX,0201h    ; function, # of sectors
  100.         int     13h        ; read system boot record
  101.         jc      Menu        ; exit if error
  102.         cmp     WORD PTR 510[BX],0aa55h ; test signature
  103.         jne     Menu        ; reprompt if invalid
  104. ;
  105. ;        Jump to secondary boot.
  106. ;        DL now contains boot disk number (80h or 81h);
  107. ;        ES:SI contains the address of partition table
  108. ;        entry to boot.
  109. ;
  110.         jmp    FAR PTR StdBaseEntry
  111.  
  112. ; -------------------------------
  113. ;
  114. ;        The main entry to the boot
  115. ;
  116. Entry:
  117.         mov    BP,DX        ; DL contains current drive number
  118.         inc    DX        ; 80h -> 81h, 81h -> 82h
  119.         xor    DL,80h+'3'    ; 80h -> '2', 81h -> '1'
  120.         mov    Base+diskNum,DL
  121. ;
  122. ;               Display the menu
  123. ;
  124. Menu:
  125.         mov     DI,Base+Partab    ; set index
  126.         mov     CX,4        ; set loop count
  127.         mov    Base+key,'1'    ; set key number in message
  128.         xor    DH,DH        ; count of partitions
  129. menuloop:
  130.         mov     BYTE PTR BootIndicator[DI],CH ; Clear active flag
  131.         mov    AL,SystemId[DI]
  132.         cmp    AL,0        ; unused partition?
  133.         je    next
  134.         cmp    AL,5        ; extended DOS partition?
  135.         je    next
  136.         inc    DH        ; increment partition count
  137.  
  138.         lea     SI,Base+FkeyMsg    ; get msg addr
  139.         call    Output
  140.  
  141.         lea    SI,Base+nameTable-2
  142. nameloop:
  143.         inc    SI
  144.         inc    SI
  145.         mov    BX,[SI]
  146.         or    BH,BH
  147.         je    endnameloop
  148.         cmp    BH,SystemId[DI]
  149.         jne    nameloop
  150.         xor    BH,BH
  151. endnameloop:
  152.         lea    SI,Base+namtab[BX]
  153.         call    Output
  154. next:
  155.         add    DI,16        ; next entry address
  156.         inc    Base+key
  157.         loop    menuloop
  158.  
  159.         cmp    BYTE PTR DS:NumDisks,2 ; is the second disk present?
  160.         je    have2disks    ; have disk 2
  161.  
  162.         lea     SI,Base+defaultMsg ; prepare 'Default' message
  163.         or    DH,DH        ; no disk 2; do we have valid partitions?
  164.         jne    prompt        ; several partitions, wait for reply
  165.  
  166.         int    18h        ; no partitions, load ROM basic
  167.         jmp    Menu        ; repeat, if no ROM basic
  168. have2disks:
  169.         lea     SI,Base+FkeyMsg    ; print 'F5'
  170.         call    Output        ; now SI points to "disk 2\nDefault..."
  171. prompt:
  172.         call    Output        ; print 'Default' message
  173. reprompt:
  174.         xor     AH,AH        ; GetTickCount
  175.         int     1ah        ; BiosTimerService
  176.         mov     BX,DX           ; lo-order tick count
  177.         add     BX,192*Timeout/10 ; timeout value in ticks
  178. ;
  179. ;               Get the reply
  180. ;
  181. waitkey:
  182.         mov     AH,1        ; keyboard status
  183.         int     16h        ; keybd bios service
  184.         jnz     reply        ; jump if reply
  185.         xor     AH,AH        ; GetTickCount
  186.         int     1ah        ; BiosTimerService
  187.         cmp     DX,BX           ; check for timeout
  188.         jb      waitkey        ; wait for scancode
  189. loaddefault:
  190.         mov     AL,Base+default    ; prior system id
  191.         jmp     testkey        ; boot default system
  192. reply:
  193.         xor     AH,AH        ; read keyboard
  194.         int     16h        ; keybd bios service
  195.         mov     AL,AH        ; Copy to AL
  196.         cmp    AL,Enter_scancode
  197.         je    loaddefault
  198.         add     AL,'1'-F1_scancode ; Turn into index
  199. testkey:
  200.         cmp     AL,'1'        ; max Function key
  201.         jb    reprompt    ; Invalid code check
  202.         cmp     AL,'5'        ; max Function key
  203.         jnbe    reprompt    ; if not F1..F5, branch
  204.         push    AX
  205.  
  206.         lea    SI,Base+newLine    ; new line
  207.         lea    BX,Base+Load
  208.         push    BX        ; call Output; jmp Load
  209.  
  210. ; -------------------------------
  211. ;
  212. ;        Output line [SI] to screen, end of line marked with 80h
  213. ;
  214. Output:
  215.         cld            ; reset direction flag
  216.         lodsb            ; load argument from string
  217.         push    AX        ; save byte
  218.         and     AL,7fh        ; insure valid character
  219.         mov     AH,14        ; write tty
  220.         int     10h        ; bios video service
  221.         pop    AX        ; restore byte
  222.         test    AL,80h        ; test for end of string
  223.         jz      Output        ; do until end of string
  224.         ret            ; return to caller
  225.  
  226. ; -------------------------------
  227. ;
  228. ;        Save boot block default partition settings
  229. ;
  230. SaveBoot:
  231.         push    SI
  232.         mov     AX,0301h    ; write sector
  233.         mov    BX,Base        ; ES already == 0
  234.         mov     CX,0001h    ; cylinder 0, sector 1
  235.         xor     DH,DH        ; drive #, head 0
  236.         int     13h        ; replace boot record
  237.         pop    SI
  238.         mov     Base+default,'?' ; reset default
  239.         ret
  240.  
  241. ; -------------------------------
  242.  
  243. newLine        db    13,10+80h
  244. FkeyMsg         db      13,10,'F'
  245. key             db      '0 . . .',' '+80h,'disk '
  246. diskNum        db    '1'
  247. defaultMsg    db    13,10,10,'Default: F'
  248. default         db      '?',' '+80h
  249.  
  250. nameTable    db      type01-namtab, 1
  251.         db      type01-namtab, 4
  252.         db      type01-namtab, 6
  253.         db      type07-namtab, 7
  254.         db    type08-namtab, 8
  255.         db      type09-namtab, 9
  256.         db      type0A-namtab, 0Ah
  257.         db      type63-namtab, 63h
  258.         db      type64-namtab, 64h
  259.         db      type64-namtab, 65h
  260.         db      type81-namtab, 80h
  261.         db      type81-namtab, 81h
  262.         db      type82-namtab, 82h
  263.         db      type93-namtab, 93h
  264.         db      typeA5-namtab, 0A5h
  265.         db      type9f-namtab, 09fh
  266.         db      type75-namtab, 75h
  267.         db      typedb-namtab, 52h
  268.         db      typedb-namtab, 0dbh
  269.         db      type40-namtab, 40h
  270.         db      typeF2-namtab, 0F2h
  271.         db      unknownPart-namtab, 0
  272.  
  273. namtab:
  274. type01          db      'do','s'+80h
  275. type07        db      'hpf','s'+80h
  276. type08        db    'fs '
  277. type09        db      'ai','x'+80h
  278. type0A          db      'os','2'+80h
  279. type63          db      'uni','x'+80h
  280. type64          db      'novel','l'+80h
  281. type81          db      'mini','x'+80h
  282. type82          db      'linu','x'+80h
  283. type93        db      'amoeb','a'+80h
  284. typeA5          db      '386bs','d'+80h
  285. type9f          db      'bsd','i'+80h
  286. type75        db      'pci','x'+80h
  287. typedb        db      'cp','m'+80h
  288. type40        db      'veni','x'+80h
  289. typeF2        db      'dosse','c'+80h
  290. unknownPart    db    '?','?'+80h
  291.  
  292. used            equ     $ - Boot
  293.         db      (1beh - used + 1) dup (0) ; error if code too big
  294.         db      63 dup (0)    ; clear rest of record
  295.         dw    0aa55h        ; magic
  296.  
  297. code        ends
  298.         end
  299.